# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dwd.tab.dwd_tab_barscan_sign_base_dt import jms_dwd__dwd_tab_barscan_sign_base_dt
from jms.dwd.tab.dwd_tab_barscan_collect_base_dt import jms_dwd__dwd_tab_barscan_collect_base_dt
from jms.dwd.tab.dwd_tab_barscan_centerarrival_base_dt import jms_dwd__dwd_tab_barscan_centerarrival_base_dt
from jms.dwd.tab.dwd_tab_reback_transfer_express_base import jms_dwd__dwd_tab_reback_transfer_express_base
from jms.dwd.tab.dwd_tab_barscan_difficult_base_dt import jms_dwd__dwd_tab_barscan_difficult_base_dt
from jms.dwd.oms.dwd_yl_oms_oms_order_incre_dt import jms_dwd__dwd_yl_oms_oms_order_incre_dt
from jms.dwd.tab.dwd_tab_barscan_taking_base_dt import jms_dwd__dwd_tab_barscan_taking_base_dt
from jms.dwd.tab.dwd_tab_barscan_warehousing_base_dt import jms_dwd__dwd_tab_barscan_warehousing_base_dt
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dwd.tab.dwd_tab_barscan_send_base_dt import jms_dwd__dwd_tab_barscan_send_base_dt
from jms.time_sensor.time_after_03_30 import time_after_03_30


# 揽收漏扫明细
dm__dm_taking_scan_miss_detail = SparkSqlOperator(
    task_id='dm__dm_taking_scan_miss_detail',
    pool_slots=11,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    execution_timeout=timedelta(minutes=90),
    name='dm__dm_taking_scan_miss_detail_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_taking_scan_miss_detail/execute.sql',
    driver_memory='12G',
    executor_memory='8G',
    executor_cores=5,
    num_executors=30,
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    conf={
        'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
        'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors': 36,  # 动态资源最大扩容 Executor 数
        'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
        'spark.executor.memoryOverhead': '4G',  # executor的堆外内存
        'spark.hadoop.hive.exec.dynamic.partition.mode': 'nonstrict', # 动态分区
        'spark.hadoop.hive.exec.dynamic.partition': 'true',
        'spark.yarn.maxAppAttempts':1,
        'spark.default.parallelism': 600,
        'spark.sql.shuffle.partitions': 600,
        'spark.core.connection.ack.wait.timeout': 5000, #增加网络连接的超时时长，executor优先从本地节点获取某份数据，获取不到会从远程节点获取，数据量大内存频繁溢出，频繁垃圾回收，spark / executor停止工作，无法提供响应
        'spark.locality.wait': 60,
        'spark.driver.maxResultSize': 20,
    },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200,
              },
    yarn_queue='pro',
)

dm__dm_taking_scan_miss_detail << [
    jms_dwd__dwd_tab_barscan_sign_base_dt,
    jms_dwd__dwd_tab_barscan_collect_base_dt,
    jms_dwd__dwd_tab_barscan_centerarrival_base_dt,
    jms_dwd__dwd_tab_reback_transfer_express_base,
    jms_dwd__dwd_tab_barscan_difficult_base_dt,
    jms_dwd__dwd_yl_oms_oms_order_incre_dt,
    jms_dwd__dwd_tab_barscan_taking_base_dt,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    jms_dim__dim_network_whole_massage,
    jms_dwd__dwd_tab_barscan_send_base_dt,
    jms_dwd__dwd_tab_barscan_warehousing_base_dt,
    time_after_03_30
]